local extension = Package:new("jianzhitupo")
extension.extensionName = "sdj"

Fk:loadTranslationTable{
  ["jianzhitupo"] = "剑之突破",
  ["jian"] = "剑",
}

local shendaijian = General(extension, "shendaijian", "wu", 7)
local qingzheng = fk.CreateTriggerSkill{
  name = "qingzheng",
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  events = {fk.CardUsing, fk.CardResponding},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and
      not table.every({ 1, 3, 5 }, function(num)
        return player:getMark("@" .. self.name) % num ~= 0
      end)
  end,
  on_use = function(self, event, player, target, data)
    local loopList = table.filter({ 1, 3, 5 }, function(num)
      return player:getMark("@" .. self.name) % num == 0
    end)

    local toObtain = {}
    for _, count in ipairs(loopList) do
      local cardList = "slash,jink"
      if count == 3 then
        cardList = "peach,analeptic"
      elseif count == 5 then
        cardList = "ex_nihilo,duel"
      end
      local randomCard = player.room:getCardsFromPileByRule(cardList)
      if #randomCard > 0 then
        table.insert(toObtain, randomCard[1])
      end
    end

    if #toObtain > 0 then
      player.room:moveCards({
        ids = toObtain,
        to = player.id,
        toArea = Card.PlayerHand,
        moveReason = fk.ReasonPrey,
        proposer = player.id,
        skillName = self.name,
      })
    end
  end,

  refresh_events = {fk.CardUsing, fk.CardResponding, fk.EventLoseSkill},
  can_refresh = function(self, event, target, player, data)
    if event == fk.EventLoseSkill then
      return target == player and data == self
    end
    return player:hasSkill(self) and target == player
  end,
  on_refresh = function(self, event, target, player, data)
    if event == fk.EventLoseSkill then
      player.room:setPlayerMark(player, "@" .. self.name, 0)
    else
      player.room:addPlayerMark(player, "@" .. self.name, 1)
    end
  end,
}
shendaijian:addSkill("luanji")
shendaijian:addSkill(qingzheng)
Fk:loadTranslationTable{
  ["shendaijian"] = "神代剑",
  ["#shendaijian"] = "古之恶来",
  ["cv:shendaijian"] = "冷泉月夜",
  ["illustrator:shendaijian"] = "小冷",
  ["qingzheng"] = "清政",
  [":qingzheng"] = "锁定技，你每使用或打出：一张牌时，你随机获得一张【杀】或【闪】；三张牌时，你随机获得一张【桃】或【酒】；"..
  "五张牌时，你随机获得一张【无中生有】或【决斗】。",

  ["~shendaijian"] = "主公，快走……！",
}












return extension